package com.blog.boot.webapp.controller.user;

import com.blog.boot.api.common.RestMsg;
import com.blog.boot.webapp.controller.common.BaseController;
import com.blog.boot.webapp.utils.UserOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.net.URLEncoder;

/**
 * @description:
 * @author : cailong
 * @Date: Created in 下午 3:42 2018/12/7 0007
 */
@Controller
@RequestMapping("/user")
public class UserController extends BaseController {
    private static final String VIEW_PATH = "/index/views/";

    //用户首页
    @RequestMapping("/index.html")
    public RestMsg.RestModelAndView index(){
        return restFactory.setModelAndView(VIEW_PATH+"user/index.html");
    }
    //用户中心
    @RequestMapping("/home.html")
    public RestMsg.RestModelAndView home(){
        return restFactory.setModelAndView(VIEW_PATH+"user/home.html");
    }

    //用户修改信息
    @RequestMapping("/set.html")
    public RestMsg.RestModelAndView set(HttpServletRequest request){
        request.getSession().setAttribute(UserOperation.CURRPAGE,"user");
        request.getSession().setAttribute(UserOperation.USERHONG,"user/set");
        return restFactory.setModelAndView(VIEW_PATH+"user/set.html");
    }

    //用户消息
    @RequestMapping("/article.html")
    public RestMsg.RestModelAndView article(HttpServletRequest request){
        request.getSession().setAttribute(UserOperation.USERHONG,"user/article");
        return restFactory.setModelAndView(VIEW_PATH+"user/article.html");
    }

    //用户消息
    @RequestMapping("/message.html")
    public RestMsg.RestModelAndView message(HttpServletRequest request){
        request.getSession().setAttribute(UserOperation.USERHONG,"user/message");
        return restFactory.setModelAndView(VIEW_PATH+"user/message.html");
    }
    //用户收藏列表
    @RequestMapping("/collection/find")
    public RestMsg find(HttpServletRequest request){
        RestMsg msg = restFactory.getMsg();
        request.getSession().setAttribute(UserOperation.USERHONG,"user/message");
        return msg;
    }

    //登录
    @RequestMapping("/login.html")
    public RestMsg.RestModelAndView login(HttpServletRequest request) {
        String referer = request.getHeader("Referer");
        String re = URLEncoder.encode(referer);
        request.setAttribute("referer",re);
        return restFactory.setModelAndView(VIEW_PATH+"user/login.html");
    }

    //注册
    @RequestMapping("/reg.html")
    public RestMsg.RestModelAndView regist() {
        return restFactory.setModelAndView(VIEW_PATH+"user/reg.html");
    }

}
